package com.hzit.interceptor;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 类名：
 * 作者：WF
 * 功能：springmvc拦截器
 */
@Component("interceptor01")   // 如果这里不指定bean的名字，默认名字就是类名首字母小写
public class FirstInterceptor implements HandlerInterceptor {

	//1. 代表在执行控制器方法前调用，返回true:代表放行，false：拦截不放行
	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
		System.out.println("FirstInterceptor---》preHandle（）");
		return true;
	}

	//2. 代表在控制器方法执行完成后调用
	@Override
	public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
		System.out.println("FirstInterceptor---》postHandle（）");
	}

	//3. 在页面渲染出来之前调用
	@Override
	public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
		System.out.println("FirstInterceptor---》afterCompletion（）");
	}


}
